package com.example.demo.design_patterns.protype;

/**
 * 原型模式(浅拷贝)
 *      原型模式就是讲一个对象作为原型，使用clone()方法来创建新的实例。
 *
 * @author: htc
 * @date: Created in 10:14 2019/3/13.
 */
public class Protype implements Cloneable {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        } finally {
            return null;
        }
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Protype protype = new Protype();
        Protype protypeNew = (Protype) protype.clone();
    }
}
